// pages/list/list.js
var app = getApp()
const util = require('../../utils/util.js')
Page({

  data: {
    active: "list",
    classNumber: "1701",
    signupTime: "2020-04-02 17:37:52",
    classes: [],
    page: 0
  },
  onLoad: function(opts) {
    this.getData(0)    
  },

  onChange(event) {
    console.log(event.detail)
    this.setData({
      active: event.detail,
    });

    let that = this
    wx.navigateTo({
      url: "/pages/" + that.data.active + "/" + that.data.active
    })
  },
  opPullDownRefresh: function(res) {

  },
  onReachBottom: function () {
    console.log("触底了！！！")
      this.getData(this.data.page + 1)    
  },
  getData(page) {
    wx.cloud.callFunction({
      name: "getSigninRecords",
      data: {
        userId: app.globalData.userInfo._id,
        page: page
      }
    }).then(res => {
      console.log(res)
      let oldValue = this.data.classes
      let newValue = res.result.data.map(record => {
        record.sinupTime = util.formatTime(new Date(record.sinupTime))
        return record
      })
      this.setData({
        page: page,
        classes: oldValue.concat(newValue)
      })
    }).catch(res => {
      console.log(res)
    })
  }
})